home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / start.s < prev    next >
Text File  |  1995-12-23  |  10KB  |  341 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #define START
  22. #include "ixemul.h"
  23. #include "version.h"
  24.  
  25. /* size of C_PRIVATE was generated by create_header.c */
  26. /* include the generated header */
  27. #include "ix_internals.h"
  28.  
  29.  
  30.     .text
  31.  
  32.    | The first executable location.  This should return an error
  33.    | in case someone tried to run you as a program (instead of
  34.    | loading you as a library).
  35.     .globl    Start        | we use this to force inclusion of start.s
  36. Start:
  37.    movel   #-1,d0
  38.    rts
  39.  
  40. |-----------------------------------------------------------------------
  41. | A romtag structure.  Both "exec" and "ramlib" look for
  42. | this structure to discover magic constants about you
  43. | (such as where to start running you from...).
  44. |-----------------------------------------------------------------------
  45.  
  46. initDDescrip:
  47.                |STRUCTURE RT,0
  48.      .word    RTC_MATCHWORD      | UWORD RT_MATCHWORD
  49.      .long    initDDescrip       | APTR  RT_MATCHTAG
  50.      .long    EndCode            | APTR  RT_ENDSKIP
  51.      .byte    RTF_AUTOINIT       | UBYTE RT_FLAGS
  52.      .byte    IX_VERSION         | UBYTE RT_VERSION
  53.      .byte    NT_LIBRARY         | UBYTE RT_TYPE
  54.      .byte    IX_PRIORITY        | BYTE  RT_PRI
  55.      .long    ixName             | APTR  RT_NAME
  56.      .long    idString           | APTR  RT_IDSTRING
  57.      .long    Init               | APTR  RT_INIT
  58. | this is just fool proof, and this library will never make it to ROM
  59. | anyway, so resident tags are not that important ;-)
  60. EndCode:
  61.  
  62.  
  63.    | this is the name that the library will have
  64. ixName:    .asciz IX_NAME
  65.  
  66.    | this is an identifier tag to help in supporting the library
  67.    | format is 'name version.revision (dd.mm.yy)',<cr>,<lf>,<null>'
  68.    | without any leading zeros in dd.mm.yy
  69. idString:
  70.     .ascii IX_IDSTRING
  71.     .byte 13 
  72.     .byte 10 
  73.     .byte 0 
  74.  
  75.    | force word alignment
  76.    .even
  77.  
  78.  
  79.    | The romtag specified that we were "RTF_AUTOINIT".  This means
  80.    | that the RT_INIT structure member points to one of these
  81.    | tables below.  If the AUTOINIT bit was not set then RT_INIT
  82.    | would point to a routine to run.
  83.  
  84. Init:
  85.    .long   IXBASE_SIZEOF    | size of library base data space
  86.    .long   funcTable        | pointer to function initializers
  87.    .long   dataTable            | pointer to data initializers
  88.    .long   initRoutine            | routine to run
  89.  
  90.  
  91. funcTable:
  92.  
  93.    |------ standard system routines
  94.    .long   Open
  95.    .long   Close
  96.    .long   Expunge
  97.    .long   Null
  98.  
  99.    |------ my libraries definitions
  100.  
  101. #define ___must_recompile220 ___must_recompile
  102. #define ___must_recompile221 ___must_recompile
  103. #define ___must_recompile222 ___must_recompile
  104. #define ___must_recompile223 ___must_recompile
  105. #define ___must_recompile224 ___must_recompile
  106. #define ___must_recompile226 ___must_recompile
  107. #define ___must_recompile229 ___must_recompile
  108. #define ___must_recompile235 ___must_recompile
  109. #define ___must_recompile237 ___must_recompile
  110. #define ___must_recompile239 ___must_recompile
  111. #define ___must_recompile240 ___must_recompile
  112. #define ___must_recompile241 ___must_recompile
  113. #define ___must_recompile242 ___must_recompile
  114. #define ___must_recompile243 ___must_recompile
  115. #define ___must_recompile244 ___must_recompile
  116. #define ___must_recompile253 ___must_recompile
  117. #define ___must_recompile254 ___must_recompile
  118. #define ___must_recompile255 ___must_recompile
  119. #define ___must_recompile256 ___must_recompile
  120. #define ___must_recompile259 ___must_recompile
  121. #define ___must_recompile262 ___must_recompile
  122. #define ___must_recompile267 ___must_recompile
  123. #define ___must_recompile273 ___must_recompile
  124. #define ___must_recompile274 ___must_recompile
  125. #define ___must_recompile275 ___must_recompile
  126. #define ___must_recompile277 ___must_recompile
  127. #define ___must_recompile386 ___must_recompile
  128. #define ___must_recompile387 ___must_recompile
  129. #define ___must_recompile388 ___must_recompile
  130. #define ___must_recompile389 ___must_recompile
  131. #define ___must_recompile390 ___must_recompile
  132. #define ___must_recompile447 ___must_recompile
  133. #define ___must_recompile448 ___must_recompile
  134. #define ___must_recompile449 ___must_recompile
  135. #define ___must_recompile450 ___must_recompile
  136.  
  137. #ifdef TRACE_LIBRARY
  138. #define SYSTEM_CALL(func, vec) .long trace_/**/func
  139. #else
  140. #define SYSTEM_CALL(func, vec) .long _/**/func
  141. #endif
  142. #include <sys/syscall.def>
  143. #undef SYSTEM_CALL
  144.  
  145.    |------ function table end marker
  146.    .long   -1
  147.  
  148. #ifdef TRACE_LIBRARY
  149. #define SYSTEM_CALL(func, vec) \
  150. trace_/**/func: ;                        \
  151.     pea _/**/func;                        \
  152.     pea vec;                         \
  153.     jsr _trace_entry;                    \
  154.     lea sp@(8),sp;                        \
  155.     tstl d0;                        \
  156.     beq  1f;        /* jump directly there */    \
  157.     /* in that case, trace_entry already provided the result */    \
  158.     movel sp@(-4),d0;                    \
  159.     rts;                            \
  160. 1:    jmp _/**/func;
  161. #include <sys/syscall.def>
  162. #undef SYSTEM_CALL
  163. #endif
  164.  
  165.  
  166.  
  167.    | The data table initializes static data structures.
  168.    | The format is specified in exec/InitStruct routines
  169.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  170.    | are in the file "exec/initializers.i".  The first argument
  171.    | is the offset from the library base for this byte/word/long.
  172.    | The second argument is the value to put in that cell.
  173.    | The table is null terminated
  174.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  175.  
  176. dataTable:
  177.     INITBYTE (LN_TYPE,         NT_LIBRARY)
  178.     INITLONG (LN_NAME,         ixName)
  179.     INITBYTE (IXBASE_FLAGS,     0x6) |LIBF_CHANGED_SUMUSED
  180.     INITWORD (IXBASE_VERSION,     IX_VERSION)
  181.     INITWORD (IXBASE_REVISION,     IX_REVISION)
  182.     INITLONG (IXBASE_IDSTRING,     idString)
  183.     .long   0
  184.  
  185.  
  186. #ifdef DEBUG
  187. twoint:
  188.     .asciz "$%lx, $%lx\n"
  189. #endif
  190.  
  191.    | This routine gets called after the library has been allocated.
  192.    | The library pointer is in D0.  The segment list is in A0.
  193.    | If it returns non-zero then the library will be linked into
  194.    | the library list.
  195. initRoutine:
  196.  
  197.    |------ get the library pointer into a convenient A register
  198.    movel   a5,sp@-
  199.    movel   d0,a5
  200.  
  201.    |------ save a pointer to our loaded code
  202.    movel   a0,a5@(IXBASE_SEGLIST)
  203.  
  204.    |------ do the higher-level initialization in C
  205.    pea       a5@
  206.    jbsr       _ix_init
  207.    lea       sp@(4),sp
  208.    movel   sp@+,a5
  209.    rts
  210.  
  211. |----------------------------------------------------------------------
  212. |
  213. | here begins the system interface commands.  When the user calls
  214. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  215. | into a call to the following routines (Open/Close/Expunge).  Exec
  216. | has already put our library pointer in A6 for us.  Exec has turned
  217. | off task switching while in these routines (via Forbid/Permit), so
  218. | we should not take too long in them.
  219. |
  220. |----------------------------------------------------------------------
  221.  
  222.  
  223.    | Open returns the library pointer in d0 if the open
  224.    | was successful.  If the open failed then null is returned.
  225.    | It might fail if we allocated memory on each open, or
  226.    | if only open application could have the library open
  227.    | at a time...
  228.  
  229. Open:      | ( libptr:a6, version:d0 )
  230.  
  231.  
  232.    |------ mark us as having another opener
  233.    addw   #1,a6@(IXBASE_OPENCNT)
  234.  
  235.    |------ prevent delayed expunges
  236.    | !!!!!!
  237.    | commo - example code uses private flags field (IXBASE_MYFLAGS), WHY????
  238.    | !!!!!!
  239.    bclr   #LIBB_DELEXP,a6@(IXBASE_FLAGS)
  240.  
  241.    |------ do other things in C
  242.    pea       a6@
  243.    jbsr       _ix_open
  244.    lea       sp@(4),sp
  245.    |--- ix_open() should return the library base, if all ok
  246.    
  247.    rts
  248.  
  249.    | There are two different things that might be returned from
  250.    | the Close routine.  If the library is no longer open and
  251.    | there is a delayed expunge then Close should return the
  252.    | segment list (as given to Init).  Otherwise close should
  253.    | return NULL.
  254.  
  255. Close:      | ( libptr:a6 )
  256.  
  257.    |------ do any cleanups needed in C
  258.    pea      a6@
  259.    jsr      _ix_close
  260.    lea      sp@(4),sp
  261.     
  262.    |------ set the return value
  263.    clrl   d0
  264.  
  265.    |------ mark us as having one fewer openers
  266.    subw   #1,a6@(IXBASE_OPENCNT)
  267.  
  268.    |------ see if there is anyone left with us open
  269.    bne    L11
  270.  
  271.    |------ see if we have a delayed expunge pending
  272.    btst   #LIBB_DELEXP,a6@(IXBASE_FLAGS)    | SEE ABOVE!
  273.    beq    L11
  274.  
  275.    |------ do the expunge
  276.    bsr    Expunge
  277. L11:
  278.    rts
  279.  
  280.  
  281.    | There are two different things that might be returned from
  282.    | the Expunge routine.  If the library is no longer open
  283.    | then Expunge should return the segment list (as given to
  284.    | Init).  Otherwise Expunge should set the delayed expunge
  285.    | flag and return NULL.
  286.    |
  287.    | One other important note: because Expunge is called from
  288.    | the memory allocator, it may NEVER Wait() or otherwise
  289.    | take long time to complete.
  290.  
  291. Expunge:   | ( libptr: a6 )
  292.  
  293.    moveml  d2/a5/a6,sp@-
  294.    movel   a6,a5
  295.    movel   4:w,a6
  296.    
  297.    |------ see if anyone has us open
  298.    tstw    a5@(IXBASE_OPENCNT)
  299.    beq     L21
  300.  
  301.    |------ it is still open.  set the delayed expunge flag
  302.    bset    #LIBB_DELEXP,a5@(IXBASE_FLAGS)    | SEE ABOVE !!
  303.    clrl       d0
  304.    bra     Expunge_End
  305.  
  306. L21:
  307.    |------ go ahead and get rid of us.  Store our seglist in d2
  308.    movel   a5@(IXBASE_SEGLIST),d2
  309.  
  310.    |------ unlink from library list
  311.    movel   a5,a1
  312.    jsr       a6@(_LVORemove)
  313.    
  314.    |
  315.    | device specific closings here...
  316.    |
  317.    pea       a5@
  318.    jsr       _ix_expunge
  319.    lea       sp@(4),sp
  320.  
  321.    |------ free our memory
  322.    clrl    d0
  323.    movel   a5,a1
  324.    movew   a5@(IXBASE_NEGSIZE),d0
  325.  
  326.    subl    d0,a1
  327.    addw    a5@(IXBASE_POSSIZE),d0
  328.  
  329.    jsr       a6@(_LVOFreeMem)
  330.  
  331.    |------ set up our return value
  332.    movel   d2,d0
  333.  
  334. Expunge_End:
  335.    moveml  sp@+,d2/a5/a6
  336.    rts
  337.  
  338. Null:
  339.    clrl    d0
  340.    rts
  341.